﻿package org.openChart.sprite.elements 
{
	import flash.events.MouseEvent;
	import org.openChart.display.DisplayElement;
	import org.openChart.display.chart.DisplayPieElement;
	import org.openChart.sprite.CommandHandler;
	import org.openChart.sprite.ContainerSprite;
	import org.openChart.sprite.util.AngleHelper;
	import org.openChart.sprite.Command;
	
	/**
	 * ...
	 * @author Chongyuan
	 */
	public class Pie3d extends ElementSprite
	{
		//var 
		public var moving:Number = 0;
		public var original_y:Number = 0;
		private var endAngle_:Number = 0;
		private var beginAngle_:Number = 0;
		
		public function Pie3d( displayElement:DisplayElement, commandHandler:CommandHandler ) 
		{
			
			super(displayElement, commandHandler);
			var pieElement:DisplayPieElement = displayObject as DisplayPieElement;
			this.endAngle_ = pieElement.endAngle;
			this.beginAngle_ = pieElement.beginAngle;
			var angleHelper:AngleHelper = new AngleHelper(this, beginAngle_, endAngle_, 3000);
			paint();
		}
		
		public override function paint():void
		{
			
			
			var pieElement:DisplayPieElement = displayObject as DisplayPieElement;
			graphics.clear();
			fillSector3d(pieElement.position.x, pieElement.position.y, pieElement.longRadius, pieElement.longRadius, beginAngle_, endAngle_, pieElement.viewAngle, pieElement.thickness, color);
		}
		
		public override function mouseUp(event:MouseEvent):void
		{
			
		}
		
		public override function mouseDown(event:MouseEvent):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, turning);
			stage.addEventListener(MouseEvent.MOUSE_UP, addMouseUp);
			original_y = event.stageY;
		}
		
		public function turning(event:MouseEvent):void
		{
			moving = (event.stageY - original_y) / 5;
			original_y = event.stageY;
			commandHandler.processCommand(Command.TUNING_PIE_CHART, this);
		}
		
		public function addMouseUp(event:MouseEvent):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, turning);
			stage.removeEventListener(MouseEvent.MOUSE_UP, addMouseUp);
		}
		
		public function set endAngle(endAngle_:Number):void
		{
			this.endAngle_ = endAngle_;
			repaint();
		}
		
		public function get endAngle():Number
		{
			return this.endAngle_;
		}
	}
	
}